<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
	if(!$_SESSION['user_id']){
		echo "<script>alert('请先登录');location='index.php';</script>";
	}

	require_once("./includes/configure.php");
	require_once("./includes/database.php");
	$db = Database::Connect();
	$sc_type = $_GET['sc_type'];
	$shoucang_dongxi_id = $_GET['dx_id'];
	//1租房            2二手房            3小区
	if($sc_type=='1'){
		$sc_type=1;
	}else if($sc_type=='2'){
		$sc_type=2;
	}else if($sc_type=='3'){
		$sc_type=3;
	}
	
	if(is_numeric($shoucang_dongxi_id)){
	}else{
		die("错误的收藏操作");
	}
	if($_GET['action']=='cancle'){
		$sql1 = "delete from shoucang where user_id=".$_SESSION['user_id']." and shoucang_leixing=".$sc_type." and  shoucang_dongxi_id=".$shoucang_dongxi_id;
		$db->Execute($sql1);
		echo "<script>alert('已取消收藏');window.history.go(-1);</script>";
	}else{
		$sql1 = "select * from shoucang where user_id=".$_SESSION['user_id']." and shoucang_leixing=".$sc_type." and  shoucang_dongxi_id=".$shoucang_dongxi_id;
		$is_sc = $db->GetSingleRow($sql1);
		if($is_sc->this_id){
			echo "<script>alert('你已收藏过了');window.history.go(-1);</script>";
			exit;
		}
		$sql = "INSERT INTO shoucang VALUES (null, ".$_SESSION['user_id'].", ".$sc_type.", ".$shoucang_dongxi_id.");";
		$db->Execute($sql);
		echo "<script>alert('收藏成功');window.history.go(-1);</script>";
	}
	$db->close();
?>
</body>